using System;
using System.IO;
using System.Text;
using TALoaders;
using TAAlert.Alerts;

namespace TAAlert.Tests
{
    using NUnit.Framework;

    [TestFixture]
    class TestAlertManager
    {
        private BaseLoader loaderM = new TestDownloader();

        [Test]
        [Category("Calculation")]
        public void saveAlertsToXml()
        {
            AlertManager alertManager = new AlertManager();

            Alert alert = new EMAAlert(loaderM, "^OMX", 3);
            alertManager.addAlert(alert);

            alert = new TwoEmaAlert(loaderM, "^GDAXI", 3, 10, 0.25);
            alertManager.addAlert(alert);

            alert = new MACDAlert(loaderM, "SRM", 4, 16, 9);
            alertManager.addAlert(alert);

            alert = new VEMAAlert(loaderM, "GLD", 10, 20, 0.20);
            alertManager.addAlert(alert);

            string tmpXmlFile = "tmpTestAlerts.xml";
            alertManager.saveAlertsToXML(tmpXmlFile);
            string referenceXmlFile = "..\\..\\Tests\\TestAlerts.xml";
            FileAssert.AreEqual(referenceXmlFile, tmpXmlFile, "Comparing saved and expected XML files");
            File.Delete(tmpXmlFile);
        }

        [Test]
        [Category("Calculation")]
        public void loadAlertsFromXml()
        {
            AlertManager alertManager = new AlertManager();

            string tmpXmlFile = "tmpLongTestAlerts.xml";
            string referenceXmlFile = "..\\..\\Tests\\LongTestAlerts.xml";
            alertManager.loadAlertsFromXML(referenceXmlFile);
            alertManager.saveAlertsToXML(tmpXmlFile);
            FileAssert.AreEqual(referenceXmlFile, tmpXmlFile, "Comparing saved and expected XML files");
            File.Delete(tmpXmlFile);
        }
    }
}
